﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO.Ports;
using System.IO;

namespace weiqijiance.外廓尺寸
{
    public class wkccwanji:wkccbass
    {
        public override bool getliucheng_artificial(string lengthxz, string widthxz, string heightxz, ref int length, ref int width, ref int height, ref int length_artificial, ref int width_artificial, ref int height_artificial, ref int artificial)
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            iniclass objini = new iniclass();
            objini.Ini(path1);
            string swenjianlujing = objini.ReadValue("外廓尺寸", "文件路径");

            string sguache = "否";
            string sjcbf = "头";
            if (flowbass.sPclass.Contains("15") || flowbass.sPclass.Contains("挂")|| flowbass.sCllx.Substring(0, 1).Contains("B") || flowbass.sCllx.Substring(0, 1).Contains("G"))
            {
                sguache = "是";
                sjcbf = "挂";
            }
            string isLbgd = "否";
            if (!string.IsNullOrEmpty(flowbass.lbgd))
            {
                if (MessageBox.Show("是否检测栏板高度", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    isLbgd = "是";
                }
            }
            string jclb = "01";
            if (flowbass.sxcrh.Contains("注册") || flowbass.sxcrh.Contains("过户") || flowbass.sxcrh.Contains("新车"))
            {
                jclb = "00";
            }
            objini.Ini(string.Format(@"{0}TestCmd.ini", swenjianlujing));
            objini.Writue("检测信息", "是否挂车", sguache);
            objini.Writue("检测信息", "检测部分", sjcbf);
            objini.Writue("检测信息", "是否检测整备质量", "否");
            objini.Writue("检测信息", "是否检测栏板高度", isLbgd);


            objini.Writue("车体部分1", "检验流水号", flowbass.jylsh);
            objini.Writue("车体部分1", "车牌号码", flowbass.sPlate);
            objini.Writue("车体部分1", "号牌种类", flowbass.sPclass);
            objini.Writue("车体部分1", "车辆类型", flowbass.sCllx);
            objini.Writue("车体部分1", "车身颜色", flowbass.scsys);
            objini.Writue("车体部分1", "车主单位", flowbass.owner);
            objini.Writue("车体部分1", "底盘号码", flowbass.svin);
            objini.Writue("车体部分1", "检验类别", jclb);
            objini.Writue("车体部分1", "出厂日期", flowbass.dCCRQ.ToString("yyyy-MM-dd"));
            objini.Writue("车体部分1", "检测线号", "1");
            objini.Writue("车体部分1", "检测次数", flowbass.iITERAT.ToString());
            objini.Writue("车体部分1", "车轴数", string.Format(@"{0}", flowbass.iVax));
            objini.Writue("车体部分1", "出厂长", flowbass.ichang.ToString());
            objini.Writue("车体部分1", "出厂宽", flowbass.ikuan.ToString());
            objini.Writue("车体部分1", "出厂高", flowbass.igao.ToString());
            objini.Writue("车体部分1", "长度上限值", lengthxz);
            objini.Writue("车体部分1", "宽度上限值", widthxz);
            objini.Writue("车体部分1", "高度上限值", heightxz);
            objini.Writue("车体部分1", "栏板高度", flowbass.lbgd.Trim().Length > 0 ? flowbass.lbgd.Trim() : "400");
            objini.Writue("车体部分1", "轴距", flowbass.szhouju);
            objini.Writue("车体部分1", "出厂质量", string.Format(@"{0}", flowbass.iCLZBZL));




            objini.Writue("车体部分2", "检验流水号", "21070116092100048");
            objini.Writue("车体部分2", "车牌号码", "晋00001");
            objini.Writue("车体部分2", "号牌种类", "大型汽车");
            objini.Writue("车体部分2", "车辆类型", "大型专项作业车");
            objini.Writue("车体部分2", "车身颜色", "蓝色");
            objini.Writue("车体部分2", "车主单位", "个人");
            objini.Writue("车体部分2", "底盘号码", "LWXSSJDJSKAS1232SD");
            objini.Writue("车体部分2", "检验类别", "01");
            objini.Writue("车体部分2", "出厂日期", "2016/04/12");
            objini.Writue("车体部分2", "检测线号", "1");
            objini.Writue("车体部分2", "检测次数", "1");
            objini.Writue("车体部分2", "车轴数", "2");
            objini.Writue("车体部分2", "出厂长", "7900");
            objini.Writue("车体部分2", "出厂宽", "2500");
            objini.Writue("车体部分2", "出厂高", "3200");
            objini.Writue("车体部分2", "栏板高度", "400");
            objini.Writue("车体部分2", "轴距", "4500");
            objini.Writue("车体部分2", "出厂质量", "4200");



            //开始测量
            //测量状态

            //结果 变量参数
            //result = "";
            //info = "";

            string lengthJudge = "";
            string heightJudge = "";
            string widthJudge = "";
            string danbangaodu = "";
            string danbangaoduPD = "";
            string danbangaoduXZ = "";


            string sdenpaixianshi = "";
            string smubiaolujin = string.Format("{0}", swenjianlujing);

            //string SPIDWK = "";// luxiangkais(idetid, "18X61", "1", "M1", "150213060048044803");


            string fullname = "";

            for (; ; )
            {


                if (!objwkcc.bwkcc)
                {
                    objwkcc.sneirongWKCC = "外廓尺寸";
                    objwkcc.WKCCshow();
                    objwkcc.setLedWritewkcc(string.Format("{0}", "外廓尺寸"), "", 1);
                    return false;
                }
                bool bbz = false;
                //break;
                //fullname = addSubDirectory(new DirectoryInfo(smubiaolujin), "*.ini");//
                foreach (FileInfo fi in (new DirectoryInfo(smubiaolujin)).GetFiles("*.ini"))
                {
                    fullname = fi.FullName;

                    //过程信息
                    if (fullname.IndexOf("TestProc.ini") > -1)//
                    {
                        objini.Ini(fullname);
                        sdenpaixianshi = objini.ReadValue("过程信息", "显示信息");
                        if (objini.ReadValue("过程信息", "抓拍信息").Contains("车头"))
                        {
                            //sendpic(idetid, "9999", swkccq, "0360", "08");
                            ////SendMessageEXX(idetid, "M1", "0360", "150213060048044803");
                            //// sendpic(idetid, "9999", swkcch, "0361", "07");
                        }
                        else if (objini.ReadValue("过程信息", "抓拍信息").Contains("车尾"))
                        {
                            //sendpic(idetid, "9999", swkcch, "0361", "08");
                            ////SendMessageEXX(idetid, "M1", "0361", "150213060048044802");
                        }
                        File.Delete(fullname);//删除文件 显示提示
                        if (sdenpaixianshi != "")
                        {
                            if (sdenpaixianshi.Length < 17)
                            {
                                //objwkcc.setLedWritewkcc(flowbass.sPlate, "缓慢驶入外廓区域", 1);
                                objwkcc.sneirongWKCC = sdenpaixianshi;
                                objwkcc.WKCCshow();
                                objwkcc.setLedWritewkcc(sdenpaixianshi, "", 1);
                            }
                        }

                    }
                    //结果
                    if (fullname.IndexOf("TestResult.ini") > -1)//得到结果退出检测
                    {
                        objini.Ini(fullname);
                        if (objini.ReadValue("结果", "检测结果数").Contains("1"))
                        {
                            int.TryParse(objini.ReadValue("车体结果1", "长"), out length);
                            int.TryParse(objini.ReadValue("车体结果1", "宽"), out width);
                            int.TryParse(objini.ReadValue("车体结果1", "高"), out height);

                            lengthJudge = objini.ReadValue("车体结果1", "长判定");
                            widthJudge = objini.ReadValue("车体结果1", "宽判定");
                            heightJudge = objini.ReadValue("车体结果1", "高判定");

                            danbangaodu = objini.ReadValue("车体结果1", "栏板高度");
                            danbangaoduPD = objini.ReadValue("车体结果1", "栏板高度判定");
                            danbangaoduXZ = objini.ReadValue("车体结果1", "栏板高度标准");
                        }
                        else
                        {
                            int.TryParse(objini.ReadValue("车体结果2", "长"), out length);
                            int.TryParse(objini.ReadValue("车体结果2", "宽"), out width);
                            int.TryParse(objini.ReadValue("车体结果2", "高"), out height);

                            lengthJudge = objini.ReadValue("车体结果2", "长判定");
                            widthJudge = objini.ReadValue("车体结果2", "宽判定");
                            heightJudge = objini.ReadValue("车体结果2", "高判定");

                            danbangaodu = objini.ReadValue("车体结果2", "栏板高度");
                            danbangaoduPD = objini.ReadValue("车体结果2", "栏板高度判定");
                            danbangaoduXZ = objini.ReadValue("车体结果2", "栏板高度标准");
                        }
                        System.Threading.Thread.Sleep(500);
                        bbz = true;
                        File.Delete(fullname);
                        break;
                    }

                }
                if (bbz)
                    break;
                //测量过程
                System.Threading.Thread.Sleep(1000);
            }
            return true;
        }


    }
}
